<?php
  /**
  * Management of collections in Real Estate Projects
  * @author: trungdt
  * @since: June 22, 2011
  * @version: 1.0
  * 
  * Change logs
  */
  if (!defined('EXPONENT')) exit('');
  
  $max_item =15;
    
  // Administrator access restrict
  if (exponent_users_isAdmin() || exponent_permissions_check('administrate',$loc))
  {
    // set flow
    exponent_flow_set(SYS_FLOW_PROTECTED,SYS_FLOW_ACTION);
    
    // pagination
    // we count all post
    $count_post = $db->countObjects('duan_collections',"location_data = '".serialize($loc)."'");

    // page split
    // cal how many posts
    $pages=floor($count_post / $max_item);
    if ($count_post % $max_item != 0)
        $pages++;

    // get page
    $page=1;
    if (isset($_REQUEST['page']))  $page=intval($_REQUEST['page']);
    if (($page<1) || ($page>$pages)) $page=1;
    $start_pos=($page-1)*$max_item;
    // end of pagination
    
    // now we dont need location_data to store all info, we query db
    $data=$db->selectObjects("bds_collections"," location_data = '".serialize($loc)."' ORDER BY rank ASC LIMIT {$start_pos},{$max_item}");
    
    $template=new template("bdsmodule","_collection_management", $loc);
    $template->assign("data",$data);
    $template->register_permissions(array('configure',"administrate"),$loc);  
    $template->assign("page",$page);
    $template->assign("pages",$pages);
    $template->assign("start_index",$start_pos); 
    $template->output();
  }
  else
  {
      echo SITE_403_HTML;
  }
?>
